package com.example.mybatisplus.service.impl;

import com.example.mybatisplus.common.utls.SessionUtils;
import com.example.mybatisplus.model.domain.DutyTime;
import com.example.mybatisplus.model.domain.UserAccount;
import com.example.mybatisplus.mapper.DutyTimeMapper;
import com.example.mybatisplus.service.DutyTimeService;
import com.example.mybatisplus.service.UserAccountService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 记录初访员和咨询师的值班时间
 * 服务实现类
 * </p>
 *
 * @author cft
 * @since 2022-06-29
 */
@Service
public class DutyTimeServiceImpl extends ServiceImpl<DutyTimeMapper, DutyTime> implements DutyTimeService {



	@Autowired
	UserAccountService userAccountService;

	@Autowired
	DutyTimeService dutyTimeService;

	/*
	 * author:cft
	 * function:修改值班时间表的教师和教室
	 * procedure:通过id和类型获得教师的名字,再进行插入
	 */
	@Override
	public void alterDutyTime(DutyTime dutyTime) {
		QueryWrapper<UserAccount> queryWrapper = new QueryWrapper<>();
		queryWrapper.eq("user_id", dutyTime.getDutyTeacherId()).eq("user_type", dutyTime.getDutyTeacherType());
		dutyTime.setDutyName(userAccountService.getOne(queryWrapper).getName()).setDutyStatus("空闲");
		dutyTimeService.updateById(dutyTime);
	}

	/*
	 * author:tqq
	 * 查询空闲的时间段
	 * */
	@Override
	public List<DutyTime> getFreeDutyTimeByDay(Integer day) {
		QueryWrapper<DutyTime> wrapper = new QueryWrapper<>();
		wrapper.eq("duty_weekday", day).eq("duty_status", "空闲");
		return dutyTimeService.list(wrapper);
	}
	/* 
	 * author:jrh
	 * function:查询空闲初访员值班时间表
	 */
	@Override
	public List<DutyTime> getFViewerDuty() {
		QueryWrapper<DutyTime> wrapper=new QueryWrapper<>();
		wrapper.eq("duty_teacher_type","初访员").eq("duty_status","空闲");
		return dutyTimeService.list(wrapper);
	}

	/*
	 * author:jrh
	 * function:查询初访员值班时间表
	 */
	@Override
	public List<DutyTime> getFDuty() {
		QueryWrapper<DutyTime> wrapper=new QueryWrapper<>();
		wrapper.eq("duty_teacher_type","初访员").eq("duty_teacher_id", SessionUtils.getCurrentUserInfo().getUserId());
		return dutyTimeService.list(wrapper);
	}

	/*
	 * author:jrh
	 * function:查询咨询师值班时间表
	 */
	@Override
	public List<DutyTime> getConTime() {
		QueryWrapper<DutyTime> wrapper=new QueryWrapper<>();
		wrapper.eq("duty_teacher_type","咨询师").eq("duty_teacher_id", SessionUtils.getCurrentUserInfo().getUserId());
		return dutyTimeService.list(wrapper);
	}

}
